﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using EmuladorSMS;

namespace EmuladorGPS
{
    class Program
    {
        static void Main(string[] args)
        {
            string portaNome = "";
            Console.WriteLine("Informe a porta:");
            Console.Title = "Emulador - Módulo GPS";
            do
            {
                portaNome = Console.ReadLine();
                if(portaNome.ToUpper().Equals("EXIT"))
                    Environment.Exit(0);

                try
                {
                    FacadeSerial.Instance.abrirPorta(portaNome, 9600);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    portaNome = "";
                }
            } while (portaNome.Equals(""));

            while (true)
            {
                string conteudo = "";
                conteudo += "$GPGGA,081153.999,1253.3973,S,03820.6532,W,0,00,0.0,17.5,M,0.0,M,,0000*56";
                conteudo += Environment.NewLine;
                conteudo += "$GPGSA,A,1,,,,,,,,,,,,,0.0,0.0,0.0*30";
                conteudo += Environment.NewLine;
                conteudo += "$GPGSV,3,1,12,12,73,129,22,05,45,101,25,25,45,203,00,09,30,349,16*72";
                conteudo += Environment.NewLine;
                conteudo += "$GPGSV,3,2,12,29,29,215,00,21,27,298,00,02,19,146,15,27,19,003,00*7B";
                conteudo += Environment.NewLine;
                conteudo += "$GPGSV,3,3,12,15,10,015,23,10,04,136,00,18,04,335,00,26,00,051,*73";
                conteudo += Environment.NewLine;
                conteudo += "$GPRMC,081153.999,V,1253.3973,S,03820.6532,W,000.0,000.0,2";
                conteudo += Environment.NewLine;
                conteudo += "$GPVTG,000.0,T,,M,000.,*72";
                conteudo += Environment.NewLine;
                conteudo += "$GPRMC,081442.999,V,1253.3973,S,03820.6532,W,000.0,000.0,240712,,,N*79";
                conteudo += Environment.NewLine;
                conteudo += "$GPVTG,000.0,T,,M,000.0,N,000.0,K,N*02";
                Console.WriteLine(conteudo);
                try
                {
                    FacadeSerial.Instance.enviarStringPorta(conteudo);
                }
                catch (Exception e) {
                    Console.WriteLine(e.Message);
                    Thread.Sleep(5000);
                    Environment.Exit(0);
                }
                Thread.Sleep(1000);
            }
        }
    }
}
